<?php 

function option($items, $parent_id, $cat_id, $level=0) {
    foreach ($items as $item) {
        if ($item['id']==$cat_id) continue;
        
        $selected = ($item['id']==$parent_id) ? 'selected' : '';
        echo '<option value="'.$item['id'].'" '.$selected.'>';
        echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level).$item['name'];
        if (isset($item['children']) && is_array($item['children'])) {
            option($item['children'], $parent_id, $cat_id, $level+1);
        }
        echo '</option>';
    }
}
?>
<form action="" method="post" class="form-horizontal ajax-submit">

	<div class="form-group">
		<label class="col-sm-1 control-label">标题</label>
		<div class="col-sm-6">
			<input type="text" class="form-control" name="title" value="<?= $info['title']?>" required>
		</div>
	</div>

	<div class="form-group">
		<label class="col-sm-1 control-label">类别</label>
		<div class="col-sm-6">
			<select name="cid" class="form-control">
				<option value="0"> -选择上级分类- </option>
    			<?php if(Arr::get($_GET, 'pid')):?>
    			<?php option($cat_tree, Arr::get($_GET, 'pid'), 0);?>
    			<?php else:?>
    			<?php option($cat_tree, $info['cid'], $info['id']);?>
    			<?php endif;?>
			</select>
		</div>
	</div>

	<div class="form-group">
		<label class="col-sm-1 control-label">摘要</label>
		<div class="col-sm-6">
			<textarea name="desc" class="form-control" rows="4"><?= $info['desc']?></textarea>
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">封面</label>
		<div class="form-group ">
            <div id="works_pic_con">
            </div>
            <div id="works_pic_btn">
                <img class="img-thumbnail" style="margin-left: 1%;" src="/static/img/default.png"/>
            </div>
        </div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-1 control-label">内容</label>
		<div class="col-sm-11">
			<textarea id="editor" name="content"><?= htmlspecialchars($info['content'])?></textarea>
		</div>
	</div>
	
	<div class="form-group">
		<div class="col-sm-offset-1 col-sm-3">
			<button type="submit" class="btn btn-primary">提交</button>
		</div>
	</div>
</form>
<?= HTML::script('static/tinymce/tinymce.min.js')?>
<?php include DOCROOT.'/views/plupload.php';?>
<script>
$(function(){
	//上传作品图片
    init_upload('works_pic_btn','works_pic_con','img');

    init_upload('works_pic_btn2','works_pic_con2','img');
})
</script>

<style>
.up-item{float:left;width:160px;margin:5px;position:relative}
.up-item .close{position:absolute;right:3px;top:0;}
.up-item .img-thumbnail{width:160px;}
.up-item .progress{position:absolute;left:0;bottom:0;width:100%;height:8px;margin:0;display:none}
</style>



<script type="text/javascript">
tinyMCE.init({
	selector : 'textarea#editor',
	plugins: [
		  		"advlist autolink lists link image charmap print preview anchor",
		  		"searchreplace visualblocks code fullscreen imagetools upload",
		  		"insertdatetime media table contextmenu paste textcolor colorpicker emoticons",
		  		"codesample eqneditor"
		  	],
  	toolbar: "upload undo redo | fontselect fontsizeselect forecolor | bold italic | link image emoticons | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | fullscreen preview",
  	autosave_ask_before_unload: false,
  	convert_urls: false,
    force_br_newlines : true,
    force_p_newlines : false,
    forced_root_block : '', // Needed for 3.x
	height : 400,
	content_css: ['<?= URL::site('static/css/preview.css')?>'],
	language: 'zh_CN'
});
</script>




